package org.study.io;

import java.util.concurrent.*;

/**
 * @author 朝花不迟暮
 * @version 1.0
 * @date 2020/9/24 10:03
 */
public class ThreadTest
{
    public static void main(String[] args)
    {
        /*ThreadLocal<Object> local = new InheritableThreadLocal<>();
        local.set("java");
        System.out.println("name: "+Thread.currentThread().getName()+" data: "+local.get());
        new Thread(()->{
            System.out.println("name: "+Thread.currentThread().getName()+" data: "+local.get());
        }).start();*/
        FutureTask<String> futureTask = new FutureTask<>(new MyCallable());
        Thread thread = new Thread(futureTask);
        thread.start();
        try
        {
            System.out.println("返回结果 " + futureTask.get(3, TimeUnit.SECONDS));
        } catch (InterruptedException e)
        {
            e.printStackTrace();
        } catch (ExecutionException e)
        {
            e.printStackTrace();
        } catch (TimeoutException e)
        {
            e.printStackTrace();
        }
    }
}

class MyCallable implements Callable<String>{
    @Override
    public String call()
    {
        return "1";
    }
}